package com.ruoyi.common.core.exception.domain;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

@Data
public class ExceptionMessage implements Serializable {

    //状态码
    private Integer status;
    /**
     * 所属模块
     */
    private String module;

    /**
     * 错误码
     */
    private String code;

    /**
     * 错误码对应的参数
     */
    private Object[] args;

    private Object data;

    /**
     * 消息
     */
    private String businessMessage;

    /**
     * 级别  INFO WARN ERROR  为了在处理异常的时候区分
     * ERROR 错误
     * WARN 警告
     * INFO 提示
     */
    private LevelEnum levelEnum;

    public ExceptionMessage(String module, String code, Object[] args, String businessMessage, LevelEnum levelEnum, Integer status, Object data) {
        this.module = module;
        this.code = code == null ? "internalServiceError" : code;
        this.args = args;
        this.businessMessage = businessMessage;
        this.levelEnum = levelEnum;
        this.levelEnum = this.levelEnum == null ? LevelEnum.ERROR : this.levelEnum;
        this.status = status == null ? HttpStatus.INTERNAL_SERVER_ERROR.value() : status;
        this.data = data;
    }

    public ExceptionMessage(String module, String code, Object[] args, String businessMessage, LevelEnum levelEnum, Integer status) {
        this(module, code, args, businessMessage, levelEnum, status, null);
    }

    public ExceptionMessage(String module, String code, Object[] args, String businessMessage) {
        this(module, code, args, businessMessage, LevelEnum.ERROR, null);
    }

    public ExceptionMessage(String module, String code, Object[] args) {
        this(module, code, args, null);
    }

    public ExceptionMessage(String module, String code, String businessMessage) {
        this(module, code, null, businessMessage);
    }

    public ExceptionMessage(String module, String businessMessage) {
        this(module, null, null, businessMessage);
    }

    public ExceptionMessage(String code, Object[] args) {
        this(null, code, args, null);
    }

    public ExceptionMessage(String businessMessage) {
        this(null, null, null, businessMessage);
    }

    public ExceptionMessage(String module, String code, String businessMessage, LevelEnum level) {
        this(module, code, null, businessMessage, level, null);
    }

    /**
     * 异常级别
     */
    public static enum LevelEnum {
        ERROR(1, "ERROR"), WARN(2, "WARN"), INFO(3, "INFO");

        private int level;// 级别
        private String des;// 级别描述

        private LevelEnum(int level, String des) {
            this.level = level;
            this.des = des;
        }

        public int getLevel() {
            return level;
        }

        public String getDes() {
            return des;
        }

    }

    public ExceptionMessage setStatus(Integer status) {
        this.status = status;
        return this;
    }

    public ExceptionMessage setModule(String module) {
        this.module = module;
        return this;
    }

    public ExceptionMessage setCode(String code) {
        this.code = code;
        return this;
    }

    public ExceptionMessage setArgs(Object[] args) {
        this.args = args;
        return this;
    }

    public ExceptionMessage setData(Object data) {
        this.data = data;
        return this;
    }

    public ExceptionMessage setBusinessMessage(String businessMessage) {
        this.businessMessage = businessMessage;
        return this;
    }

    public ExceptionMessage setLevelEnum(LevelEnum levelEnum) {
        this.levelEnum = levelEnum;
        return this;
    }


}
